package com.javadaemon.Tinderbox.gui;

import com.javadaemon.Tinderbox.Constants;
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

/**
 * This file is part of Tinderbox.
 *
 * Tinderbox is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Ponix is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Tinderbox.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * The menubar used for the ControlPanel
 * @author Mads Horndrup
 */
public class MenuBar extends JMenuBar {

    /** The first menu, called "file" */
    JMenu fileMenu;

    /** The different options in the first menu */
    JMenuItem exitOption, hideOption, websiteOption;
    ControlPanel parent;

    public MenuBar(ControlPanel frame) {
        this.parent = frame;
        // Set up the first menu.
        fileMenu = new JMenu("File");
        this.add(fileMenu);

        // Set up the menu items for the first menu.
        // Starting with websiteOption
        websiteOption = new JMenuItem("Visit homepage");
        fileMenu.add(websiteOption);
        websiteOption.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                try {
                    Desktop.getDesktop().browse(java.net.URI.create(Constants.HOMEPAGE_URL));
                } catch (IOException ex) {
                    JOptionPane.showMessageDialog(new JFrame(), "No default browser found!");
                }
            }
        });

        hideOption = new JMenuItem("Hide tools (F9)");
        fileMenu.add(hideOption);
        hideOption.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                parent.toggleHide();
            }
        });

        // Next is the exitOption
        exitOption = new JMenuItem("Exit tools");
        fileMenu.add(exitOption);
        exitOption.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                parent.destroy();
            }
        });
        
        
    }
}
